<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<t:layout title="Cars - Instasale">
    <h3>Available Cars:</h3>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>ID</th>
            <th><a href="/cars?sortBy=model">Model</a></th>
            <th>Description</th>
            <th><a href="/cars?sortBy=engine_type">Engine Type</a></th>
            <th><a href="/cars?sortBy=used">Used car</a></th>
            <th><a href="/cars?sortBy=seller_id">Seller</a></th>
            <th>Features</th>
            <th><a href="/cars?sortBy=mileage">Mileage</a></th>
            <th><a href="/cars?sortBy=price">Price $</a></th>
            <th><a href="/cars?sortBy=available_date">Available starting</a></th>
            <th>Actions</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="car" items="${carList}">
            <tr>
                <td>${car.id}</td>
                <td><a href="/cars/${car.id}">${car.model}</a></td>
                <td>${car.description}</td>
                <td>${car.engineType.description}</td>
                <td>${(car.used) ? "Yes" : "No" }</td>
                <td>${car.seller.title}</td>
                <td>
                    <ul>
                        <c:forEach var="feature" items="${car.features}">
                            <li>${feature.description}</li>
                        </c:forEach>
                    </ul>
                </td>
                <td>${(car.mileage > 0) ? car.mileage : "No"}</td>
                <td>${car.price}</td>
                <td>${car.availableDate}</td>
                <td>
                    <form:form method="delete" action="/cars/${car.id}/delete">
                        <input type="submit" value="Delete" class="btn btn-small btn-danger"/>
                    </form:form>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</t:layout>